package com.skeeey.aim.service.dao.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.skeeey.aim.model.Role;
import com.skeeey.aim.service.dao.RoleDao;

public class RoleDaoImpl extends TempleteDaoImpl<Role, String> implements RoleDao {

	@SuppressWarnings("unchecked")
	@Override
	public Role findRoleBy(String roleName) {
		Role role = null;
		DetachedCriteria criteria = DetachedCriteria.forClass(Role.class);
		criteria.add(Restrictions.eq("name", roleName));
		List<Role> roles = this.getHibernateTemplate().findByCriteria(criteria);
		if(roles.size() > 0) {
			role = roles.get(0);
		}
		return role;
	}

}
